package user

import (
	"github.com/bgmp/config"
	"github.com/bgmp/handler"
	"github.com/bgmp/model"
	"github.com/gin-gonic/gin"
	log "github.com/sirupsen/logrus"
)

func (b Base) DeleteBg(c *gin.Context, req *DeleteBgRequest) *DeleteBgResponse {
	// 开启事务
	tx := config.DB.Begin()
	// 完成之后提交事务
	defer tx.Commit()
	var err error
	// 遍历数组
	for _, id := range req.Ids {
		bg := &model.Bg{}
		bg.ID = id
		err = bg.Delete(tx)
		if err != nil {
			// 出错事务回滚
			tx.Rollback()
			handler.Errorf(c, "删除记录失败")
			log.Error(err)
			break
		}
	}
	return &DeleteBgResponse{}
}

type DeleteBgRequest struct {
	Ids []uint `json:"ids"`
}

type DeleteBgResponse struct {
}
